home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v10n22.arc / NEWCMD.ASM < prev    next >
Assembly Source File  |  1991-12-08  |  7KB  |  146 lines

  1. NEWCMD.ASM
  2.  
  3. ;****************************************************************************
  4. ; NEWCMD illustrates how interrupt 2Fh, functions AE00h and AE01h can be
  5. ; used to add new internal commands to DOS.  NEWCMD installs a replacement
  6. ; for the CLS command that clears the screen to white on blue when CLS is
  7. ; typed on the command line.  Requires DOS 3.3 or higher.
  8. ;****************************************************************************
  9.  
  10. color           equ     1Fh                     ;Colors to clear the screen
  11.                                                 ;  to (default=white on blue)
  12. code            segment
  13.                 assume  cs:code
  14.                 org     100h
  15. begin:          jmp     init
  16.  
  17. command         db      3,"CLS"                 ;Command text
  18. int2Fh          dd      ?                       ;Interrupt 2Fh vector
  19.  
  20. ;****************************************************************************
  21. ; MPLEX_INT handles calls to interrupt 2Fh.
  22. ;****************************************************************************
  23.  
  24. mplex_int       proc    far
  25.                 pushf                           ;Save FLAGS
  26.                 sti                             ;Interrupts on
  27.                 cmp     ax,0AE00h               ;Branch if this is
  28.                 je      check_cmd               ;  function AE00h
  29.                 cmp     ax,0AE01h               ;Also branch if it's
  30.                 je      exec_cmd                ;  function AE01h
  31. mplex_exit:     popf                            ;Restore FLAGS and chain
  32.                 jmp cs:[int2Fh]                 ;  the interrupt
  33.  
  34. check_cmd:      call    compare                 ;Inspect the command string
  35.                 jne     mplex_exit              ;Exit if it's not CLS
  36.                 mov     al,0FFh                 ;Set AL to FFh and exit
  37.                 popf                            ;  if it is
  38.                 iret
  39.  
  40. exec_cmd:       call    compare                 ;Inspect the command string
  41.                 jne     mplex_exit              ;Exit if it's not CLS
  42.                 mov     byte ptr [si],00h       ;Nullify the string
  43.                 call    cls                     ;Clear the command from the
  44.                 popf                            ;  buffer and exit
  45.                 iret
  46. mplex_int       endp
  47.  
  48. ;****************************************************************************
  49. ; COMPARE returns with the Z flag set if the command pointed to by DS:SI
  50. ; is "CLS," or with Z clear if it's not.
  51. ;****************************************************************************
  52.  
  53. compare         proc    near
  54.                 push    cx                      ;Save registers
  55.                 push    si
  56.                 push    di
  57.                 push    es
  58.                 push    cs                      ;Point ES:DI to command
  59.                 pop     es                      ;  text in this segment
  60.                 mov     di,offset command
  61.                 cld                             ;Clear direction flag
  62.                 mov     cx,4                    ;Compare up to four bytes
  63.                 repe    cmpsb                   ;Compare while equal
  64.                 pop     es                      ;Restore registers and exit
  65.                 pop     di
  66.                 pop     si
  67.                 pop     cx
  68.                 ret
  69. compare         endp
  70.  
  71. ;****************************************************************************
  72. ; CLS clears the screen.
  73. ;****************************************************************************
  74.  
  75. cls             proc    near
  76.                 push    ax                      ;Save registers
  77.                 push    bx
  78.                 push    cx
  79.                 push    dx
  80.                 push    ds
  81.  
  82.                 mov     ah,12h                  ;See if an EGA or VGA is
  83.                 mov     bl,10h                  ;  installed
  84.                 int     10h
  85.                 mov     ax,40h                  ;Point DS to the BIOS data
  86.                 mov     ds,ax                   ;  area
  87.                 mov     ax,0600h                ;Prepare for call to
  88.                 mov     bh,color                ;  function 06h in the
  89.                 xor     cx,cx                   ;  video BIOS
  90.                 mov     dh,24
  91.                 cmp     bl,10h                  ;Branch if this is a CGA
  92.                 je      getcols                 ;  or MDA
  93.                 mov     dh,ds:[84h]             ;Get line count from BIOS
  94. getcols:        mov     dl,ds:[4Ah]             ;Get column count, too
  95.                 dec     dl                      ;Decrement it
  96.                 int     10h                     ;Clear the screen
  97.                 mov     ah,02h                  ;Home the cursor by calling
  98.                 mov     bh,ds:[62h]             ;  function 02h in the video
  99.                 xor     dx,dx                   ;  BIOS
  100.                 int     10h
  101.  
  102.                 pop     ds                      ;Restore registers and exit
  103.                 pop     dx              
  104.                 pop     cx
  105.                 pop     bx
  106.                 pop     ax
  107.                 ret
  108. cls             endp
  109.  
  110. ;****************************************************************************
  111. ; INIT makes the program resident in memory.
  112. ;****************************************************************************
  113.  
  114. errmsg          db      "Requires DOS 3.3 or higher",13,10,"$"
  115.  
  116. init            proc    near
  117.                 assume  cs:code,ds:code
  118.  
  119.                 mov     ah,30h                  ;Get DOS version number
  120.                 int     21h                     ;  with function 30h
  121.                 xchg    ah,al                   ;Swap AH and AL
  122.                 cmp     ax,031Eh                ;Branch if this is version
  123.                 jae     install                 ;  3.30 or higher
  124.  
  125.                 mov     ah,9                    ;Display error message
  126.                 mov     dx,offset errmsg
  127.                 int     21h
  128.                 mov     ax,4C01h                ;Exit with ERRORLEVEL=1
  129.                 int     21h
  130.  
  131. install:        mov     ax,352Fh                ;Get current interrupt 2Fh
  132.                 int     21h                     ;  vector and save it
  133.                 mov     word ptr int2Fh,bx
  134.                 mov     word ptr int2Fh[2],es
  135.                 mov     ax,252Fh                ;Point interrupt 2Fh to
  136.                 mov     dx,offset mplex_int     ;  MPLEX_INT routine
  137.                 int     21h
  138.  
  139.                 mov     ax,3100h
  140.                 mov     dx,(offset errmsg - offset code + 15) shr 4
  141.                 int     21h
  142. init            endp
  143.  
  144. code            ends
  145.                 end     begin
  146.